<?php

class MyDB_risk_scope extends SQLite3
{
    function __construct()
    {
        $this->open('../../python/pi_sql_web.db');
    }
}


$db = new MyDB_risk_scope();
if (!$db) {
    echo $db->lastErrorMsg();
} else {
    //echo "Opened database successfully\n";
}

$tit = array();

$sql = <<<EOF
                    SELECT * FROM risk_district where is_true = 'true';
          EOF;
$ret = $db->query($sql);
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
    //echo count($row);//7
    $longitude_latitude = $row['longitude_latitude'];
    $title = $row['title'];
    $path = $title . "_path";
    echo 'var ' . $path . ' = [';
    foreach (explode("|", $longitude_latitude) as $val) {
        echo "[" . $val . "],";
        //$lo_la[]="[".$val."]";
    }
    echo '];';

    echo <<<POLYGON
                      
                    var $title = new AMap.Polygon({
                    path: $path,
                    strokeColor: "#f13c22",
                    strokeWeight: 6,
                    strokeOpacity: 0.2,
                    fillOpacity: 0.4,
                    fillColor: '#f97d1c',
                    zIndex: 50,
                    bubble: true,
                    })
            POLYGON;
    echo ';';
    $tit[] = $title;
    //echo $title;
}
$polygon = '';
foreach ($tit as $value) {
    $polygon = $polygon . $value . ",";
}
echo 'map.add([' . $polygon . '])';
$db->close();
